<extend name="Public:template" />
<block name="page_body">
<!-- 商品列表页面  -->
<include file="Public:header_productsearch"/>
<div class="productList" id="productListView">
</div>
<div class="loadingData" style="text-align:center; margin-top:10px;display:none;"  >
	<img src="__ROOT__/statics/mobile/images/ajax_loading.gif">
</div>
<div class='morePageBtn' style="display:none"><a href="#" id="morePageBtn"  >显示更多商品</a></div>
<form method="get" action="{:U('Tuangou/list')}" name="form_search" id="form_search">
	<input type="hidden" name="name"   value="{$search.name}"/>
</form>
</block>
<block name="script_footer">
<!-- 商品显示模板  -->
<script type="text/javascript" src="__ROOT__/statics/mobile/scripts/template.min.js"></script>
<script id="productTmpl" type="text/html">
<dl>
	<dt class="pull-left">
		<a href="javascript:showDetail('<%=prod_id%>');">
			<img class="lazy"  src="<%=prod_pic%>"/>
		</a>
	</dt>
	<dd>
		<a href="javascript:showDetail('<%=prod_id%>');">
			<h5><%=name%> <%=prod_spec%></h5>
			<p class="promTags"></p>
			<p class="price">
				<span class="now">¥<%=price_real%></span>
				<span class="old">¥<%=price_sale%></span>
			</p>
		</a>
		<span class="cartItemNum alert-info" id="itemNum<%=prod_id%>"></span>
		<a class="detailBtn"  href="javascript:showDetail('<%=prod_id%>');" >详细</a>
	</dd>
</dl>
</script>
<script type="text/javascript">
$(document).ready(function(){
	searchProduct();
	//输入搜索条件自动查询数据
	$(".morePageBtn").on( "click", function(event, ui) {
		searchProduct();
		return false;
	});
})
function searchProduct(){
	$(".morePageBtn").hide();
	$(".loadingData").clone().appendTo("#productListView");
	$("#productListView .loadingData").show();
	if($("#form_search").attr('action')!=''){
		$.ajax({
	        'url': $("#form_search").attr('action'),
	        'dataType': "json",
	        'data': $('#form_search').serialize(),
	        'success': function (data) {
	        	var list = data['list'];
	        	var page = data['page'];
	        	$.each(list,function(i,item){
	        		var productItemHtml = template.render('productTmpl', item);
	        		$(productItemHtml).appendTo("#productListView");
	        	});
	        	$("#form_search").attr('action',page['downPageUrl'])
	        	if(page['totalPages']==page['nowPage']){
	        		$(".morePageBtn").hide();
	        	}else{
	        		$(".morePageBtn").show();
	        	}
	        	$("#productListView .loadingData").remove();
	        }
	    });
	}

}
function showDetail(prod_id){
	document.location.href = "/Tuangou/showDetail.html?prod_id="+prod_id;
}
</script>
</block>